src/libostree/ostree-repo-file.c \
src/libostree/ostree-repo-file-enumerator.c \
src/libostree/ostree-repo-file-enumerator.h \
+ src/libostree/ostree-sysroot.c \
+ src/libostree/ostree-sysroot.h \
$(NULL)
if USE_LIBARCHIVE
libostree_1_la_SOURCES += src/libostree/ostree-libarchive-input-stream.h \
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2013 Colin Walters <walters@verbum.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "otutil.h"
+#include "libgsystem.h"
+
+#include "ostree-sysroot.h"
+
+/**
+ * SECTION:libostree-sysroot
+ * @title: Root partition mount point
+ * @short_description: Manage physical root filesystem
+ *
+ * A #OstreeSysroot object represents a physical root filesystem,
+ * which in particular should contain a toplevel /ostree directory.
+ * Inside this directory is an #OstreeRepo in /ostree/repo, plus a set
+ * of deployments in /ostree/deploy.
+ */
+
+struct OstreeSysroot {
+ GObject parent;
+
+ GFile *path;
+ int sysroot_fd;
+};
+
+typedef struct {
+ GObjectClass parent_class;
+} OstreeSysrootClass;
+
+enum {
+ PROP_0,
+
+ PROP_PATH
+};
+
+G_DEFINE_TYPE (OstreeSysroot, ostree_sysroot, G_TYPE_OBJECT)
+
+static void
+ostree_sysroot_finalize (GObject *object)
+{
+ OstreeSysroot *self = OSTREE_SYSROOT (object);
+
+ g_clear_object (&self->path);
+
+ G_OBJECT_CLASS (ostree_sysroot_parent_class)->finalize (object);
+}
+
+static void
+ostree_sysroot_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ OstreeSysroot *self = OSTREE_SYSROOT (object);
+
+ switch (prop_id)
+ {
+ case PROP_PATH:
+ /* Canonicalize */
+ self->path = g_file_new_for_path (gs_file_get_path_cached (g_value_get_object (value)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ostree_sysroot_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ OstreeSysroot *self = OSTREE_SYSROOT (object);
+
+ switch (prop_id)
+ {
+ case PROP_PATH:
+ g_value_set_object (value, self->path);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ostree_sysroot_constructed (GObject *object)
+{
+ OstreeSysroot *self = OSTREE_SYSROOT (object);
+
+ g_assert (self->path != NULL);
+
+ G_OBJECT_CLASS (ostree_sysroot_parent_class)->constructed (object);
+}
+
+static void
+ostree_sysroot_class_init (OstreeSysrootClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = ostree_sysroot_constructed;
+ object_class->get_property = ostree_sysroot_get_property;
+ object_class->set_property = ostree_sysroot_set_property;
+ object_class->finalize = ostree_sysroot_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_PATH,
+ g_param_spec_object ("path",
+ "",
+ "",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+ostree_sysroot_init (OstreeSysroot *self)
+{
+ self->sysroot_fd = -1;
+}
+
+/**
+ * ostree_sysroot_new:
+ * @path: Path to a system root directory
+ *
+ * Returns: (transfer full): An accessor object for an system root located at @path
+ */
+OstreeSysroot*
+ostree_sysroot_new (GFile *path)
+{
+ return g_object_new (OSTREE_TYPE_SYSROOT, "path", path, NULL);
+}
+
+/**
+ * ostree_sysroot_new_default:
+ *
+ * Returns: (transfer full): An accessor for the current visible root / filesystem
+ */
+OstreeSysroot*
+ostree_sysroot_new_default (void)
+{
+ gs_unref_object GFile *rootfs = g_file_new_for_path ("/");
+ return ostree_sysroot_new (rootfs);
+}
+
+/**
+ * ostree_sysroot_get_path:
+ * @self:
+ *
+ * Returns: (transfer none): Path to rootfs
+ */
+GFile *
+ostree_sysroot_get_path (OstreeSysroot *self)
+{
+ return self->path;
+}
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2013 Colin Walters <walters@verbum.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#pragma once
+
+#include "ostree-repo.h"
+
+G_BEGIN_DECLS
+
+#define OSTREE_TYPE_SYSROOT ostree_sysroot_get_type()
+#define OSTREE_SYSROOT(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SYSROOT, OstreeSysroot))
+#define OSTREE_IS_SYSROOT(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SYSROOT))
+
+GType ostree_sysroot_get_type (void);
+
+OstreeSysroot* ostree_sysroot_new (GFile *path);
+
+OstreeSysroot* ostree_sysroot_new_default (void);
+
+GFile *ostree_sysroot_get_path (OstreeSysroot *self);
+
+G_END_DECLS
+
G_BEGIN_DECLS
typedef struct OstreeRepo OstreeRepo;
+typedef struct OstreeSysroot OstreeSysroot;
typedef struct OstreeMutableTree OstreeMutableTree;
typedef struct OstreeRepoFile OstreeRepoFile;
#include <ostree-repo.h>
#include <ostree-mutable-tree.h>
#include <ostree-repo-file.h>
+#include <ostree-sysroot.h>
#include <ostree-diff.h>
};
gboolean
-ot_admin_builtin_cleanup (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_cleanup (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (!ot_admin_cleanup (sysroot, cancellable, error))
+ if (!ot_admin_cleanup (ostree_sysroot_get_path (sysroot), cancellable, error))
goto out;
ret = TRUE;
};
gboolean
-ot_admin_builtin_deploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
const char *refspec;
refspec = argv[1];
- if (!ot_admin_get_repo (sysroot, &repo, cancellable, error))
+ if (!ot_admin_get_repo (ostree_sysroot_get_path (sysroot), &repo, cancellable, error))
goto out;
- if (!ot_admin_list_deployments (sysroot, ¤t_bootversion, ¤t_deployments,
+ if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion, ¤t_deployments,
cancellable, error))
{
g_prefix_error (error, "While listing deployments: ");
/* Find the currently booted deployment, if any; we will ensure it
* is present in the new deployment list.
*/
- if (!ot_admin_require_deployment_or_osname (sysroot, current_deployments,
+ if (!ot_admin_require_deployment_or_osname (ostree_sysroot_get_path (sysroot), current_deployments,
opt_osname,
&booted_deployment,
cancellable, error))
if (!ostree_repo_resolve_rev (repo, refspec, FALSE, &revision, error))
goto out;
- if (!ot_admin_deploy (sysroot, current_bootversion, current_deployments,
+ if (!ot_admin_deploy (ostree_sysroot_get_path (sysroot), current_bootversion, current_deployments,
opt_osname, revision, origin,
opt_kernel_argv, opt_retain,
booted_deployment, NULL,
};
gboolean
-ot_admin_builtin_diff (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_diff (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- repo_path = g_file_resolve_relative_path (sysroot, "ostree/repo");
+ repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
- if (!ot_admin_list_deployments (sysroot, &bootversion, &deployments,
+ if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), &bootversion, &deployments,
cancellable, error))
{
g_prefix_error (error, "While listing deployments: ");
goto out;
}
- if (!ot_admin_require_deployment_or_osname (sysroot, deployments,
+ if (!ot_admin_require_deployment_or_osname (ostree_sysroot_get_path (sysroot), deployments,
opt_osname, &deployment,
cancellable, error))
goto out;
goto out;
}
- deployment_dir = ot_admin_get_deployment_directory (sysroot, deployment);
+ deployment_dir = ot_admin_get_deployment_directory (ostree_sysroot_get_path (sysroot), deployment);
orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
};
gboolean
-ot_admin_builtin_init_fs (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
};
gboolean
-ot_admin_builtin_os_init (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_os_init (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (!ot_admin_ensure_initialized (sysroot, cancellable, error))
+ if (!ot_admin_ensure_initialized (ostree_sysroot_get_path (sysroot), cancellable, error))
goto out;
if (argc < 2)
osname = argv[1];
- deploy_dir = ot_gfile_get_child_build_path (sysroot, "ostree", "deploy", osname, NULL);
+ deploy_dir = ot_gfile_get_child_build_path (ostree_sysroot_get_path (sysroot), "ostree", "deploy", osname, NULL);
/* Ensure core subdirectories of /var exist, since we need them for
* dracut generation, and the host will want them too. Note that at
};
gboolean
-ot_admin_builtin_status (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_status (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
GOptionContext *context;
gboolean ret = FALSE;
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (!ot_admin_list_deployments (sysroot, &bootversion, &deployments,
+ if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), &bootversion, &deployments,
cancellable, error))
{
g_prefix_error (error, "While listing deployments: ");
goto out;
}
- if (!ot_admin_find_booted_deployment (sysroot, deployments,
+ if (!ot_admin_find_booted_deployment (ostree_sysroot_get_path (sysroot), deployments,
&booted_deployment,
cancellable, error))
goto out;
{
int subbootversion;
- if (!ot_admin_read_current_subbootversion (sysroot, bootversion,
+ if (!ot_admin_read_current_subbootversion (ostree_sysroot_get_path (sysroot), bootversion,
&subbootversion,
cancellable, error))
goto out;
};
gboolean
-ot_admin_builtin_undeploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_undeploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
GOptionContext *context;
deploy_index_str = argv[1];
deploy_index = atoi (deploy_index_str);
- if (!ot_admin_list_deployments (sysroot, ¤t_bootversion, ¤t_deployments,
+ if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion, ¤t_deployments,
cancellable, error))
{
g_prefix_error (error, "While listing deployments: ");
goto out;
}
- if (!ot_admin_find_booted_deployment (sysroot, current_deployments, &booted_deployment,
+ if (!ot_admin_find_booted_deployment (ostree_sysroot_get_path (sysroot), current_deployments, &booted_deployment,
cancellable, error))
goto out;
g_ptr_array_remove_index (current_deployments, deploy_index);
- if (!ot_admin_write_deployments (sysroot, current_bootversion,
+ if (!ot_admin_write_deployments (ostree_sysroot_get_path (sysroot), current_bootversion,
current_bootversion ? 0 : 1, current_deployments,
cancellable, error))
goto out;
g_print ("Deleted deployment %s.%d\n", ot_deployment_get_csum (target_deployment),
ot_deployment_get_deployserial (target_deployment));
- if (!ot_admin_cleanup (sysroot, cancellable, error))
+ if (!ot_admin_cleanup (ostree_sysroot_get_path (sysroot), cancellable, error))
{
g_prefix_error (error, "Performing final cleanup: ");
goto out;
};
gboolean
-ot_admin_builtin_upgrade (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error)
+ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
GOptionContext *context;
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (!ot_admin_list_deployments (sysroot, ¤t_bootversion,
+ if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion,
¤t_deployments,
cancellable, error))
{
goto out;
}
- if (!ot_admin_require_deployment_or_osname (sysroot, current_deployments,
+ if (!ot_admin_require_deployment_or_osname (ostree_sysroot_get_path (sysroot), current_deployments,
opt_osname,
&booted_deployment,
cancellable, error))
merge_deployment = ot_admin_get_merge_deployment (current_deployments, opt_osname,
booted_deployment);
- deployment_path = ot_admin_get_deployment_directory (sysroot, merge_deployment);
+ deployment_path = ot_admin_get_deployment_directory (ostree_sysroot_get_path (sysroot), merge_deployment);
deployment_origin_path = ot_admin_get_deployment_origin_path (deployment_path);
- repo_path = g_file_resolve_relative_path (sysroot, "ostree/repo");
+ repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
repo = ostree_repo_new (repo_path);
if (!ostree_repo_open (repo, cancellable, error))
goto out;
else
{
gs_unref_object GFile *real_sysroot = g_file_new_for_path ("/");
- if (!ot_admin_deploy (sysroot,
+ if (!ot_admin_deploy (ostree_sysroot_get_path (sysroot),
current_bootversion, current_deployments,
opt_osname, new_revision, origin,
NULL, FALSE,
cancellable, error))
goto out;
- if (opt_reboot && g_file_equal (sysroot, real_sysroot))
+ if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
{
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
#pragma once
-#include <gio/gio.h>
+#include <ostree.h>
G_BEGIN_DECLS
-gboolean ot_admin_builtin_os_init (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_install (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_init_fs (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_undeploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_deploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_cleanup (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_status (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_diff (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
-gboolean ot_admin_builtin_upgrade (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_os_init (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_install (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_undeploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_cleanup (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_status (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_diff (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
+gboolean ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
G_END_DECLS
typedef struct {
const char *name;
- gboolean (*fn) (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error);
+ gboolean (*fn) (int argc, char **argv, OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
} OstreeAdminCommand;
static OstreeAdminCommand admin_subcommands[] = {
const char *opt_sysroot = "/";
const char *subcommand_name = NULL;
OstreeAdminCommand *subcommand;
- gs_unref_object GFile *sysroot = NULL;
+ gs_unref_object GFile *sysroot_path = NULL;
+ gs_unref_object OstreeSysroot *sysroot = NULL;
gboolean want_help = FALSE;
int in, out, i;
gboolean skip;
goto out;
}
- sysroot = g_file_new_for_path (opt_sysroot);
+ sysroot_path = g_file_new_for_path (opt_sysroot);
+ sysroot = ostree_sysroot_new (sysroot_path);
if (!subcommand->fn (argc, argv, sysroot, cancellable, error))
goto out;